﻿#include <QFile>
#include "CSensorSeriesTrandChart.h"
#include "CGlobal.h"
#include "CLogOper.h"
#include "CSensorSeriesOper.h"
#include "Public.h"

CSensorSeriesTrandChart::CSensorSeriesTrandChart(CDevSensorSeries* pDev,int nChannel,QWidget *parent)
	: m_pDev(pDev),m_nChannel(nChannel),QWidget(parent)
{
	ui.setupUi(this);
	ui.labelChannel->hide();
	ui.comboBoxChannel->hide();
	m_pDevData = m_pDev->m_pDevData;
	m_pTrandTooltip = new QCPToolTip(ui.widgetTrandChart);
	m_pTrandTooltip->setFont(QFont("Arial", 12));
	m_pTrandTooltip->setTextColor(Qt::black);
	m_pTrandTooltip->setBorderPen(QPen(Qt::black));
	m_pTrandTooltip->setBrush(QBrush(Qt::yellow));
	m_pTrandTooltip->setRadius(10, 10);  // 设置圆角
	m_pTrandTooltip->setOffset(5, 5);   // 设置偏移量

	m_pAccelerationTooltip = new QCPToolTip(ui.widgetAcceleration);
	m_pAccelerationTooltip->setFont(QFont("Arial", 12));
	m_pAccelerationTooltip->setTextColor(Qt::black);
	m_pAccelerationTooltip->setBorderPen(QPen(Qt::black));
	m_pAccelerationTooltip->setBrush(QBrush(Qt::yellow));
	m_pAccelerationTooltip->setRadius(10, 10);  // 设置圆角
	m_pAccelerationTooltip->setOffset(5, 5);   // 设置偏移量

	m_pMediaPlayer = new QMediaPlayer(this);
	m_audioData.clear();

	initConnect();
	initUi();
}

CSensorSeriesTrandChart::CSensorSeriesTrandChart(CDevSensorSeries* pDev, QWidget *parent /*= nullptr*/)
	: m_pDev(pDev), QWidget(parent)
{
	ui.setupUi(this);
	m_pDevData = m_pDev->m_pDevData;
	m_pTrandTooltip = new QCPToolTip(ui.widgetTrandChart);
	m_pTrandTooltip->setFont(QFont("Arial", 12));
	m_pTrandTooltip->setTextColor(Qt::black);
	m_pTrandTooltip->setBorderPen(QPen(Qt::black));
	m_pTrandTooltip->setBrush(QBrush(Qt::yellow));
	m_pTrandTooltip->setRadius(10, 10);  // 设置圆角
	m_pTrandTooltip->setOffset(5, 5);   // 设置偏移量

	m_pAccelerationTooltip = new QCPToolTip(ui.widgetAcceleration);
	m_pAccelerationTooltip->setFont(QFont("Arial", 12));
	m_pAccelerationTooltip->setTextColor(Qt::black);
	m_pAccelerationTooltip->setBorderPen(QPen(Qt::black));
	m_pAccelerationTooltip->setBrush(QBrush(Qt::yellow));
	m_pAccelerationTooltip->setRadius(10, 10);  // 设置圆角
	m_pAccelerationTooltip->setOffset(5, 5);   // 设置偏移量

	m_pMediaPlayer = new QMediaPlayer(this);
	m_audioData.clear();
	for (int i = 0; i < 8; i++)
	{
		ui.comboBoxChannel->addItem(QString::number(i + 1));
	}
	connect(ui.comboBoxChannel, &QComboBox::currentTextChanged, this, &CSensorSeriesTrandChart::onComboBoxTextChanged);
	initConnect();
	initUi();
	slotQuery();
}

CSensorSeriesTrandChart::~CSensorSeriesTrandChart()
{}

void CSensorSeriesTrandChart::initConnect()
{
	connect(ui.pushButtonQuery, &QPushButton::clicked, this, &CSensorSeriesTrandChart::slotQuery);
	connect(m_pDevData, &CDevDataSensorSeries::sigResult, this, &CSensorSeriesTrandChart::slotResult);
	connect(ui.widgetTrandChart, &QCustomPlot::mouseMove, this, &CSensorSeriesTrandChart::slotTrandChartMouseMove);
	connect(ui.widgetAcceleration, &QCustomPlot::mouseMove, this, &CSensorSeriesTrandChart::slotAccelerationMouseMove);
	// 连接 plottableClick 信号
	connect(ui.widgetTrandChart, &QCustomPlot::plottableClick, this, &CSensorSeriesTrandChart::slotPlottableClick);
}

void CSensorSeriesTrandChart::setStyleSheetFile()
{
	QString sQssPath = ":/qss/styleSheet.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	this->setStyleSheet(qss.readAll());
}

void CSensorSeriesTrandChart::initUi()
{
	ui.radioButtonX->setChecked(true);
	//默认查询当天的数据
	QDateTime timeTo = QDateTime::currentDateTime();
	timeTo.setTime(QTime::fromString("23:59:59", "hh:mm:ss"));
	QDateTime timeFrom = QDateTime::currentDateTime();
	timeFrom.setTime(QTime::fromString("00:00:00", "hh:mm:ss"));
	ui.dateTimeEditStart->setDateTime(timeFrom);
	ui.dateTimeEditEnd->setDateTime(timeTo);
	ui.dateTimeEditStart->setCalendarPopup(true);
	ui.dateTimeEditEnd->setCalendarPopup(true);

	//初始化趋势统计图
	ui.widgetTrandChart->plotLayout()->insertRow(0);
	QCPTextElement* title = new QCPTextElement(ui.widgetTrandChart, A2T("趋势图"), QFont("sans", 14, QFont::Bold));
	ui.widgetTrandChart->plotLayout()->addElement(0, 0, title);
	ui.widgetTrandChart->setInteraction(QCP::iRangeDrag, true); //鼠标单击拖动
	ui.widgetTrandChart->setInteraction(QCP::iRangeZoom, true); //滚轮滑动缩放
	ui.widgetTrandChart->xAxis->setLabel(A2T("时间"));
	ui.widgetTrandChart->yAxis->setLabel(A2T("值(温度℃/加速度g)"));
	ui.widgetTrandChart->xAxis->rescale();// 自适应x轴范围
	ui.widgetTrandChart->yAxis->rescale();// 自适应y轴范围
	 // 使用 QCPAxisTickerDateTime 来设置时间轴的格式
	QSharedPointer<QCPAxisTickerDateTime> dateTimeTicker(new QCPAxisTickerDateTime);
	dateTimeTicker->setDateTimeFormat("yyyy-MM-dd HH:mm:ss");  // 时间格式
	ui.widgetTrandChart->xAxis->setTicker(dateTimeTicker); // 设置 X 轴刻度为时间刻度
	// 设置 X 轴的显示范围为当天的时间
	ui.widgetTrandChart->xAxis->setRange(timeFrom.toSecsSinceEpoch(), timeTo.toSecsSinceEpoch());

	//创建温度曲线
	ui.widgetTrandChart->addGraph();
	ui.widgetTrandChart->graph(0)->setPen(QPen(Qt::blue));  // 蓝色曲线
	ui.widgetTrandChart->graph(0)->setName(A2T("温度(°C)"));
	ui.widgetTrandChart->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 2)); // 设置散点样式
	ui.widgetTrandChart->graph(0)->setLineStyle((QCPGraph::LineStyle::lsNone));//线为散点
	//创建加速度曲线
	ui.widgetTrandChart->addGraph();
	ui.widgetTrandChart->graph(1)->setPen(QPen(Qt::red));  // 曲线
	ui.widgetTrandChart->graph(1)->setName(A2T("加速度(g)"));
	ui.widgetTrandChart->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 2)); // 设置散点样式
	ui.widgetTrandChart->graph(1)->setLineStyle((QCPGraph::LineStyle::lsNone));//线为散点

	// 设置图例
	ui.widgetTrandChart->legend->setVisible(true);
	ui.widgetTrandChart->replot();

	//初始化加速度图表
	ui.widgetAcceleration->plotLayout()->insertRow(0);
	QCPTextElement* title2 = new QCPTextElement(ui.widgetAcceleration, A2T("加速度"), QFont("sans", 14, QFont::Bold));
	ui.widgetAcceleration->plotLayout()->addElement(0, 0, title2);
	ui.widgetAcceleration->setInteraction(QCP::iRangeDrag, true); //鼠标单击拖动
	ui.widgetAcceleration->setInteraction(QCP::iRangeZoom, true); //滚轮滑动缩放
	ui.widgetAcceleration->xAxis->setLabel(A2T("时间(s)"));
	// 使用 QCPAxisTickerDateTime 来设置时间轴的格式
	QSharedPointer<QCPAxisTickerDateTime> dateTimeTicker2(new QCPAxisTickerDateTime);
	dateTimeTicker2->setDateTimeFormat("yyyy-MM-dd HH:mm:ss");  // 时间格式
	ui.widgetAcceleration->xAxis->setTicker(dateTimeTicker2); // 设置 X 轴刻度为时间刻度
	// 设置 X 轴的显示范围为当天的时间
	ui.widgetAcceleration->xAxis->setRange(timeFrom.toSecsSinceEpoch(), timeTo.toSecsSinceEpoch());
	ui.widgetAcceleration->yAxis->setLabel(A2T("加速度(g)"));
	ui.widgetAcceleration->xAxis->rescale();// 自适应x轴范围
	ui.widgetAcceleration->yAxis->rescale();// 自适应y轴范围
	ui.widgetAcceleration->yAxis->setRange(-1, 1); // 假设温度范围是 [0, 20]

	//创建加速度曲线
	ui.widgetAcceleration->addGraph();
	ui.widgetAcceleration->graph(0)->setPen(QPen(Qt::red));  // 曲线
	ui.widgetAcceleration->graph(0)->setName(A2T("加速度(g)"));
	ui.widgetAcceleration->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 2)); // 设置散点样式
	ui.widgetAcceleration->graph(0)->setLineStyle((QCPGraph::LineStyle::lsNone));//线为散点

	// 设置图例
	ui.widgetAcceleration->legend->setVisible(true);
	ui.widgetAcceleration->replot();

	ui.labelAcceleration->setText(A2T("请先点击趋势图节点"));
}

void CSensorSeriesTrandChart::analyHistoryData(QString sResult)
{
	QVector<SHistryData> vecHistryData;
	// 解析 JSON 字符串
	QJsonDocument doc = QJsonDocument::fromJson(sResult.toLocal8Bit());
	if (!doc.isNull()) 
	{
		QJsonObject rootObj = doc.object();

		// 获取顶层的字段
		if (rootObj.contains("responseStatus"))
		{
			QString responseStatus = rootObj["responseStatus"].toString();
			if (responseStatus == "NO MATCH")
			{
				SExecLog ExecLog;
				ExecLog.m_sDevName = m_pDevData->m_sDevName;
				ExecLog.m_sFuncName = A2T("历史数据解析");
				ExecLog.m_sDescriptionl = A2T("没有匹配的数据");
				ExecLog.m_nAlarmLevel = enDevAlarm;
				CLogOper::instance().addMsg(ExecLog);
				return;
			}
		}
		
		// 获取 matchResults 数组
		QJsonArray matchResultsArray = rootObj["MatchResults"].toArray();
		for (int i = 0; i < matchResultsArray.size(); ++i)
		{
			QJsonObject matchObj = matchResultsArray[i].toObject();
			if (matchObj.contains("childDevID")&& matchObj.contains("date")&& matchObj.contains("sensorDataList"))
			{
				int nChildDevID = matchObj["childDevID"].toString().toInt();
				if (nChildDevID == m_nChannel)
				{
					QString sDataTime = matchObj["date"].toString();
					// 获取 sensorDataList 数组
					QJsonArray sensorDataListArray = matchObj["sensorDataList"].toArray();
					SHistryData stHistoryData;
					stHistoryData.sTime = sDataTime;
					for (int j = 0; j < sensorDataListArray.size(); ++j)
					{
						QJsonObject sensorDataObj = sensorDataListArray[j].toObject();
						if (sensorDataObj.contains("sensorDataType") && sensorDataObj.contains("currentvalue"))
						{
							if (sensorDataObj["sensorDataType"].toString() == "temperature")
							{
								stHistoryData.dTemperatureData= sensorDataObj["currentvalue"].toDouble();
							}
							else if (sensorDataObj["sensorDataType"].toString() == "acceleration")
							{
								stHistoryData.dAccelerationData = sensorDataObj["currentvalue"].toDouble();
							}
						}
					}
					vecHistryData.push_back(stHistoryData);
				}
			}
			else
			{
				SExecLog ExecLog;
				ExecLog.m_sDevName = m_pDevData->m_sDevName;
				ExecLog.m_sFuncName = A2T("历史数据解析");
				ExecLog.m_sDescriptionl = A2T("响应格式不匹配");
				ExecLog.m_nAlarmLevel = enDevAlarm;
				CLogOper::instance().addMsg(ExecLog);
				continue;
			}
		}
	}
	else
	{
		SExecLog ExecLog;
		ExecLog.m_sDevName = m_pDevData->m_sDevName;
		ExecLog.m_sFuncName = A2T("历史数据解析");
		ExecLog.m_sDescriptionl = A2T("查询历史记录时解析响应数据错误");
		ExecLog.m_nAlarmLevel = enDevAlarm;
		CLogOper::instance().addMsg(ExecLog);
		return;
	}

	if (vecHistryData.size() > 0)
	{
		QVector<double> timeData;
		QVector<double> temperatureData;
		QVector<double> accelerationData;
		for (const auto &entry : vecHistryData)
		{
			double timeStamp = QDateTime::fromString(entry.sTime,"yyyy-MM-ddTHH:mm:ss+08:00").toMSecsSinceEpoch() / 1000.0;  // 转换时间为秒
			timeData.append(timeStamp);
			temperatureData.push_back(entry.dTemperatureData);
			accelerationData.push_back(entry.dAccelerationData);
		}
		ui.widgetTrandChart->xAxis->setRange(timeData.first(), timeData.last());  // X 轴范围根据数据调整
		ui.widgetTrandChart->yAxis->setRange(-20, 50); // 假设温度范围是 [0, 20]
		//绘制温度曲线
		ui.widgetTrandChart->graph(0)->setData(timeData, temperatureData);
		ui.widgetTrandChart->graph(1)->setData(timeData, accelerationData);
		ui.widgetTrandChart->replot();
		ui.widgetTrandChart->update();
	}
}

void CSensorSeriesTrandChart::analyAcceleration(QString sFile)
{
	logText(A2T("m_ClickedTime:%1").arg(m_ClickedTime.toString("yyyy/MM/dd hh:mm:ss")));
	//界面清除
	QVector<double> vecX;
	QVector<double> vecY;
	vecX.clear();
	vecY.clear();
	ui.widgetAcceleration->graph(0)->setData(vecX, vecY);
	ui.widgetAcceleration->replot(); // 重新绘制图表
	QStringList slist = sFile.split("\n");
	int nCountTime = 0;
	QString sStartTime = "";
	for (int i = 0; i < slist.size(); i++)
	{
		if (slist[i].contains(A2T("采样时长")))
		{
			QString sCountTime = slist[i].split(",")[1];
			nCountTime = sCountTime.remove("s").toInt();
		}
		if (slist[i].contains(A2T("开始采样时间")))
		{
			if (slist[i].split(",")[1] != "")
			{
				sStartTime = QDateTime::fromString(slist[i].split(",")[1], "yyyy-MM-ddTHH:mm:ss+08:00").toString("yyyy/MM/dd hh:mm:ss");
			}
			else
			{
				sStartTime=m_ClickedTime.toString("yyyy/MM/dd hh:mm:ss");
			}
			logText(sStartTime);
		}
		if (nCountTime > 0 && sStartTime != "")
		{
			break;
		}
	}
	
	QVector<double> vecValue;
	if (slist.size() > 6)
	{
		for (int i = 6; i < slist.size(); i++)
		{
			vecValue.push_back(slist[i].split(",")[0].toDouble());
		}
	}
	double n = double(nCountTime) / vecValue.size();
	double dKey = m_ClickedTime.toMSecsSinceEpoch()/ 1000.0;
	QVector<double> vecKey;
	for (int i = 0; i < vecValue.size(); i++)
	{
		vecKey.push_back(dKey);
		dKey = dKey + n;
	}
	QString sEndTime = QDateTime::fromString(sStartTime, "yyyy/MM/dd hh:mm:ss").addSecs(nCountTime).toString("yyyy/MM/dd hh:mm:ss");
	ui.labelAcceleration->setText(A2T("%1-%2数据").arg(sStartTime).arg(sEndTime));
	ui.widgetAcceleration->graph(0)->setData(vecKey, vecValue);
	ui.widgetAcceleration->xAxis->setRange(vecKey.first(), vecKey.last());  // X 轴范围根据数据调整
	ui.widgetAcceleration->replot();
}

void CSensorSeriesTrandChart::analyAudio(QString sFile)
{
	ui.pushButtonPalyAudio->setEnabled(true);
	m_audioData = QByteArray::fromBase64(sFile.toUtf8());
	QBuffer *audioBuffer = new QBuffer(&m_audioData, this);
	audioBuffer->open(QIODevice::ReadOnly);
	m_pMediaPlayer->setMedia(QMediaContent(), audioBuffer);
}

void CSensorSeriesTrandChart::slotQuery()
{
	//界面清除
	QVector<double> vecX;
	QVector<double> vecY;
	vecX.clear();
	vecY.clear();
	ui.widgetTrandChart->graph(0)->setData(vecX, vecY);
	ui.widgetTrandChart->graph(1)->setData(vecX, vecY);
	ui.widgetTrandChart->replot(); // 重新绘制图表

	//加速度界面清除
	vecX.clear();
	vecY.clear();
	ui.widgetAcceleration->graph(0)->setData(vecX, vecY);
	ui.widgetAcceleration->replot(); // 重新绘制图表
	ui.labelAcceleration->setText(A2T("请先点击趋势图节点"));

	ui.pushButtonPalyAudio->setEnabled(false);
	m_audioData.clear();

	int nDataDirection=0;
	if (ui.radioButtonX->isChecked())
	{
		nDataDirection = 1;
	}
	if (ui.radioButtonY->isChecked())
	{
		nDataDirection = 2;
	}
	if (ui.radioButtonZ->isChecked())
	{
		nDataDirection = 3;
	}
	QString sTimeStart = ui.dateTimeEditStart->dateTime().toString("yyyy-MM-ddTHH:mm:ss+08:00");
	QString sTimeEnd = ui.dateTimeEditEnd->dateTime().toString("yyyy-MM-ddTHH:mm:ss+08:00");
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_pDev->m_sDevGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_nCtrDevType = enOntology;//设备本体
	stCtrInfo.m_nCtrCmd = ERequestType::enSearchHistoryData;
	SCtrSensorSeriesInfo* pCtrSensorSeriesInfo = new SCtrSensorSeriesInfo();
	pCtrSensorSeriesInfo->nChannel = m_nChannel;
	pCtrSensorSeriesInfo->nDataDirection = nDataDirection;
	strcpy(pCtrSensorSeriesInfo->szStartTime, sTimeStart.toLocal8Bit().data());
	strcpy(pCtrSensorSeriesInfo->szEndTime, sTimeEnd.toLocal8Bit().data());
	stCtrInfo.m_pCtrSensorSeriesInfo = pCtrSensorSeriesInfo;
	m_pDev->ctrDev(stCtrInfo);
}

void CSensorSeriesTrandChart::slotResult(int nRequestType, QString sResult)
{
	if (nRequestType == ERequestType::enSearchHistoryData)
	{
		analyHistoryData(sResult);
	}
	if (nRequestType == ERequestType::enGetAcceleration)
	{
		analyAcceleration(sResult);
	}
	if (nRequestType == ERequestType::enGetAudio)
	{
		analyAudio(sResult);
	}
}

void CSensorSeriesTrandChart::slotTrandChartMouseMove(QMouseEvent *event)
{
	// 获取鼠标在图表中的位置
	double x = ui.widgetTrandChart->xAxis->pixelToCoord(event->pos().x());
	double y = ui.widgetTrandChart->yAxis->pixelToCoord(event->pos().y());

	// 获取最接近的时间索引
	int closestIndex = -1;
	double minDistance = std::numeric_limits<double>::max();

	// 遍历温度和加速度数据，找出最接近鼠标的点
	for (int i = 0; i < ui.widgetTrandChart->graph(0)->data()->size(); ++i)
	{
		double timePoint = ui.widgetTrandChart->graph(0)->data()->at(i)->key;  // 获取时间点
		double distance = std::abs(timePoint - x);  // 计算与鼠标 x 坐标的距离

		if (distance < minDistance) 
		{
			minDistance = distance;
			closestIndex = i;
		}
	}

	if (closestIndex >= 0) 
	{
		// 获取对应的数据
		double time = ui.widgetTrandChart->graph(0)->data()->at(closestIndex)->key;
		double temperature = ui.widgetTrandChart->graph(0)->data()->at(closestIndex)->value;
		double acceleration = ui.widgetTrandChart->graph(1)->data()->at(closestIndex)->value;

		// 创建显示的文本
		QString text = QString(A2T("时间: %1\n温度(℃): %2\n加速度(g): %3"))
			.arg(QDateTime::fromMSecsSinceEpoch(time*1000).toString("yyyy/MM/dd hh:mm:ss"))
			.arg(temperature)
			.arg(acceleration);

		// 在图表中显示文本
		m_pTrandTooltip->setText(text);
		// 设置文本的位置
		m_pTrandTooltip->updatePosition(event->pos());

		ui.widgetTrandChart->replot();
	}
}

void CSensorSeriesTrandChart::slotAccelerationMouseMove(QMouseEvent *event)
{
	// 获取鼠标在图表中的位置
	double x = ui.widgetAcceleration->xAxis->pixelToCoord(event->pos().x());
	double y = ui.widgetAcceleration->yAxis->pixelToCoord(event->pos().y());

	// 获取最接近的时间索引
	int closestIndex = -1;
	double minDistance = std::numeric_limits<double>::max();

	// 遍历温度和加速度数据，找出最接近鼠标的点
	for (int i = 0; i < ui.widgetAcceleration->graph(0)->data()->size(); ++i)
	{
		double timePoint = ui.widgetAcceleration->graph(0)->data()->at(i)->key;  // 获取时间点
		double distance = std::abs(timePoint - x);  // 计算与鼠标 x 坐标的距离

		if (distance < minDistance)
		{
			minDistance = distance;
			closestIndex = i;
		}
	}

	if (closestIndex >= 0)
	{
		// 获取对应的数据
		double time = ui.widgetAcceleration->graph(0)->data()->at(closestIndex)->key;
		double acceleration = ui.widgetAcceleration->graph(0)->data()->at(closestIndex)->value;

		// 创建显示的文本
		QString text = QString(A2T("时间(s): %1\n加速度(g): %2"))
			.arg(QDateTime::fromMSecsSinceEpoch(time * 1000).toString("yyyy/MM/dd hh:mm:ss"))
			.arg(acceleration);

		// 在图表中显示文本
		m_pAccelerationTooltip->setText(text);
		// 设置文本的位置
		m_pAccelerationTooltip->updatePosition(event->pos());

		ui.widgetAcceleration->replot();
	}
}

void CSensorSeriesTrandChart::slotPlottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event)
{
	// 获取鼠标在图表中的位置
	double x = ui.widgetTrandChart->xAxis->pixelToCoord(event->pos().x());
	// 获取最接近的时间索引
	int closestIndex = -1;
	double minDistance = std::numeric_limits<double>::max();

	// 遍历温度和加速度数据，找出最接近鼠标的点
	for (int i = 0; i < ui.widgetTrandChart->graph(0)->data()->size(); ++i)
	{
		double timePoint = ui.widgetTrandChart->graph(0)->data()->at(i)->key;  // 获取时间点
		double distance = std::abs(timePoint - x);  // 计算与鼠标 x 坐标的距离

		if (distance < minDistance)
		{
			minDistance = distance;
			closestIndex = i;
		}
	}
	double time = 0;
	if (closestIndex >= 0)
	{
		// 获取对应的数据
		time = ui.widgetTrandChart->graph(0)->data()->at(closestIndex)->key;
		double temperature = ui.widgetTrandChart->graph(0)->data()->at(closestIndex)->value;
		double acceleration = ui.widgetTrandChart->graph(1)->data()->at(closestIndex)->value;
	}
	QString sTime = QDateTime::fromMSecsSinceEpoch(time*1000).toString("yyyy-MM-ddTHH:mm:ss+08:00");
	logText(A2T("点击时间:%1").arg(sTime));
	m_ClickedTime = QDateTime::fromMSecsSinceEpoch(time * 1000);
	logText(A2T("m_ClickedTime:%1").arg(m_ClickedTime.toString("yyyy/MM/dd hh:mm:ss")));
	int nDataDirection = 0;
	if (ui.radioButtonX->isChecked())
	{
		nDataDirection = 1;
	}
	if (ui.radioButtonY->isChecked())
	{
		nDataDirection = 2;
	}
	if (ui.radioButtonZ->isChecked())
	{
		nDataDirection = 3;
	}
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = m_pDev->m_sDevGuid;
	stCtrInfo.m_bCtrSync = true;
	stCtrInfo.m_nCtrDevType = enOntology;//设备本体
	stCtrInfo.m_nCtrCmd = ERequestType::enGetSensorCollectDataFile;
	SCtrSensorSeriesInfo* pCtrSensorSeriesInfo = new SCtrSensorSeriesInfo();
	pCtrSensorSeriesInfo->nChannel = m_nChannel;
	pCtrSensorSeriesInfo->nDataDirection = nDataDirection;
	strcpy(pCtrSensorSeriesInfo->szStartTime, sTime.toLocal8Bit().data());
	stCtrInfo.m_pCtrSensorSeriesInfo = pCtrSensorSeriesInfo;
	m_pDev->ctrDev(stCtrInfo);
}

void CSensorSeriesTrandChart::slotPlayAudio()
{
	if (m_audioData.size() == 0)
	{
		messageBox(0, A2T("无音频可播放"));
		return;
	}
	m_pMediaPlayer->play();
}

void CSensorSeriesTrandChart::onComboBoxTextChanged(const QString &text)
{
	m_nChannel = ui.comboBoxChannel->currentText().toInt();
}
